<template>
	<view class="u-p-30">
		<view class="bg-white radius20 u-m-b-30" @click="$u.route('/pages/subpage/wallet/rptForm')">
			<view class="title u-border-bottom">
				<view class="">
					<text>发票抬头</text>
				</view>
			</view>
			<view class="" style="padding: 20rpx 30rpx;">
				<text class="u-type-primary">+ 新增</text>
			</view>
		</view>
		<view class="bg-white radius20 u-m-b-30" v-for="(item,index) in list" :key="index">
			<view class="title u-border-bottom">
				<view class="">
					<text class="u-m-r-20">发票抬头</text>
					<u-tag mode="plain" text="默认" type="success" size="mini" v-if="item.is_default"></u-tag>
				</view>
				<view class="u-flex">
					<view class="u-m-r-20" @click="deleteHandle(item.id)">
						<u-icon name="trash" size="34"></u-icon>
					</view>

					<view class="" @click="$u.route('/pages/subpage/wallet/rptForm',{id:item.id})">
						<image src="/static/icon/edite.png" mode="aspectFill" style="width: 34rpx;height: 34rpx;"></image>
					</view>
				</view>
			</view>
			<view class="" style="padding: 20rpx 30rpx;">
				{{item.name}}
			</view>
		</view>
		<u-modal v-model="deleteModal" @confirm="deleteConfirmHandle" ref="deleteModal" :async-close="true"
			content="确定删除该发票抬头吗？" show-cancel-button confirm-color="#FFAA44"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				deleteModal: false,
				currid: ''
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				this.$u.api.invoiceList({
					page: 1,
					limit: 99
				}).then(res => {
					this.list = res
				})
			},
			// 删除
			deleteHandle(id) {
				this.currid = id;
				this.deleteModal = true
			},
			deleteConfirmHandle() {
				this.$u.api.invoiceDelete(this.currid).then(res => {
					this.deleteModal = false
					this.$u.toast("抬头已删除")
					this.getList()
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.title {
		height: 70rpx;
		padding: 0 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: $u-light-color;
	}
</style>